/*
 * File Name: CheckBoxRenderer.java
 */

package co.edu.uniandes.intercon.client.gui.cell;

import java.awt.Component;

import javax.swing.JComponent;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;

import co.edu.uniandes.intercon.client.gui.util.IconHelper;
import co.edu.uniandes.intercon.client.model.BaseP2PApplicationTableModel;
import co.edu.uniandes.intercon.core.model.EApplicationType;

/**
 * Rendered used to show a <code>image</cdoe> component in a specified cell 
 * of a grid
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 * @see co.edu.uniandes.intercon.client.gui.cell.ApplicationTypeRenderer#changeColors(JComponent,
 *      JTable, int)
 */
@SuppressWarnings("serial")
public class ApplicationTypeRenderer extends DefaultTableCellRenderer {

	/**
	 * Creates a new Renderer instance
	 */
	public ApplicationTypeRenderer() {
		super();
	}

	/**
	 * @see TableCellRenderer#getTableCellRendererComponent(JTable, Object,
	 *      boolean, boolean, int, int)
	 */
	public Component getTableCellRendererComponent(JTable table,
			java.lang.Object value, boolean isSelected, boolean hasFocus,
			int row, int column) {

		super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
				row, column);

		EApplicationType appType = ((BaseP2PApplicationTableModel) table
				.getModel()).getRecord(row).getType();
		setText("");
		setHorizontalAlignment(0);
		RendererHelper.changeColors(this, table, row);

		if (appType == EApplicationType.FILE) {
			this.setIcon(IconHelper.FILE_ICON);
		} else if (appType == EApplicationType.PROCESS) {
			this.setIcon(IconHelper.PROCESSOR_ICON);
		}

		return this;
	}

}
